#include <iostream>
using namespace std;
// compliation: g++ -o auto auto.cc -std=c++11
// 返回类型后置，auto为返回值占位符
auto func(int a, int b) -> int { return a + b; }

class Base {
 public:
  virtual void f() { std::cout << "Base::f()" << std::endl; }
};
class Derived : public Base {
  virtual void f() override { std::cout << "Derived::f()" << std::endl; }
};

void Test1() {
  Base* d = new Derived();
  // auto b = *d;  // auto会直接推导为Base，发生了对象切片
  auto& b = *d;
  d->f();
  b.f();
}

void Test2() {
  int a = 10;
  int b = 20;
  // 需要C++14
  auto l = [](auto& a, auto& b) -> auto& {
    a = a + b;
    return a;
  };
  cout << l(a, b) << endl;
}
int main() {
  // Test1();
  // cout << func(4, 5) << endl;
  Test2();
  return 0;
}